package com.dianshan.controller;


import com.dianshan.entity.Address;
import com.dianshan.entity.dto.AddressDto;
import com.dianshan.service.IAddressService;
import com.domain.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaolong
 * @since 2024-06-18
 */
@RestController
@RequestMapping("/address")
@Slf4j
@Api(tags = "地址信息管理系统")
public class AddressController {

    @Autowired
    IAddressService addressService;

    @PostMapping("/list")
    @ApiOperation("地址查询接口")
    public PageResult<Address> listAddress(@RequestBody  PageQuery pageQuery){

        PageResult<Address> pageResult = addressService.listOne(pageQuery);

        return pageResult;

    }

    @ApiOperation("地址修改接口")
    @PutMapping("/update")
    public Result<AddressDto> modifyAddress(@RequestBody Address address){

        return Result.success(addressService.updateAddress(address));
    }

    @ApiOperation("地址添加接口")
    @PostMapping("/add")
    public Result addAddress(@RequestBody Address address){
        addressService.appendAddress(address);

        return Result.success();
    }


    @ApiOperation("地址删除接口")
    @DeleteMapping("/delete/{id}")
    public Result<String> removeAddress(@PathVariable Long id){

        addressService.deleteAddress(id);
        return Result.success();
    }

    @ApiOperation("ID地址查询接口")
    @GetMapping("/select/{id}")
    public Result<AddressDto> selectAddress(@PathVariable Long id){

        return Result.success( addressService.selectAddress(id));
    }

    /**
     * 设置默认地址
     *
     * @param address
     * @return
     */
    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public Result setDefault(@RequestBody Address address) {

        addressService.setDefault(address);
        return Result.success();
    }









}
